<template>
      <dialog_item :dialogTitle="dialogTitle" @onBtnDialogClick="onBtnDialogClick" :visible.sync="dialogVisible" dialogClass='user_detail padding0Dialog'
       :btnDialogArr="btnDialogArr" :dialogHeader="{isShow:true,icon:'icon-icon_yh_off',title:dialogTitle}"
      >
        <div class="tabsContent">
        <el-tabs v-model="activeName"  @tab-click="handleClick">
        <el-tab-pane name="baseInfo" :label="$t('baseInfo')"></el-tab-pane>
        <el-tab-pane name="depUser" :label="$t('dep_user')"></el-tab-pane>
        <el-tab-pane name="settingInfo" :label="$t('settingInfo')"></el-tab-pane>
        <el-tab-pane name="proxySetting" :label="$t('proxy_setting')"></el-tab-pane>
        <el-tab-pane name="moreSetting" :label="$t('more_setting')"></el-tab-pane>
        <el-tab-pane name="moreInfo" :label="$t('moreInfo')"></el-tab-pane>
      </el-tabs>
     </div>
     <div class="userDetail width100 overflowy" ref="userDetail" :style="{ height: scrollHeight + 'px' }"  @scroll.passive="getScroll($event)">
      <!-- 用户详情 -->
      <el-form
        ref="form"
        :model="content"
        label-position="top"
        label-width="180px"
        size="small"
        :rules="rules"
        class="user-form paddingLeft0"
        
      >
      <div class="partContent">
      <div class="part elDialogBbody" id="baseInfo" ref="baseInfo">
            <p class="smallHeader">{{ $t("baseInfo") }}</p>
        <!-- (ID: {{content.id}}) -->
        <el-row>
          <el-col :span="8">
            <el-form-item :label="$t('username')" prop="name"   >
              <el-input type="text" v-model="content.name" :disabled="(isOpen && !isAdmin) || (isOpen && isSecret)"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8" :offset="4">
            <el-form-item :label="$t('loginno')" prop="loginno"   >
              <el-input type="text" v-model="content.loginno"  :disabled="(isOpen && !isAdmin) || (isOpen && isSecret) || loginnoFlag" @blur="handleBlur"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item :label="$t('password')" prop="loginpwd"    >
              <el-input type="password" v-model="content.loginpwd"  @change="changePwd" :disabled="isnewUser ? false : (isOpen && isAdmin) || (isOpen && !isSecret)"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8" :offset="4">
            <el-form-item :label="$t('confirm_pwd')" prop="confirmpwd"    >
              <el-input type="password" v-model="content.confirmpwd"  @change="changePwd" :disabled="isnewUser ? false : (isOpen && isAdmin) || (isOpen && !isSecret)"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row class="labelSlot">
          <el-col :span="8">
            <el-form-item >
              <template #label>
                <div class="df">
                <span class="greyColor">{{$t('tel') + '1'}}</span>
                <span>
                  <span class="marginR10 greyColor">{{$t('public')}}</span>
                  <el-checkbox v-model="content.telephonePublic"  :disabled="(isOpen && !isAdmin) || (isOpen && isSecret)"></el-checkbox>
                </span>
              </div>
           </template>
              <el-input type="text" v-model="content.telephone" :disabled="(isOpen && !isAdmin) || (isOpen && isSecret)">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8" :offset="4">
            <el-form-item :label="$t('superior')"    >
              <el-input :value="content.superior?content.superior.name:''"
              :disabled="(isOpen && !isAdmin) || (isOpen && isSecret) "
              clearable :placeholder="$t('placeholder_select')"
              @clear="onClearSuperiorBtn"
              :popper-append-to-body="false"
              class="width100">
              <template slot="append">
                <el-button @click="onSuperiorUserBtnClick" class="chooseBtn" :disabled="(isOpen && !isAdmin) || (isOpen && isSecret)">
                <i class="el-icon-user"></i>
              </el-button>
              </template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row class="labelSlot">
          <el-col :span="8">
            <el-form-item>
              <template #label>
                <div class="df">
                <span class="greyColor">{{$t('tel') + '2'}}</span>
                <span>
                  <span class="marginR10 greyColor">{{$t('public')}}</span>
                  <el-checkbox v-model="content.telephonePublic2" :disabled="(isOpen && !isAdmin) || (isOpen && isSecret) "></el-checkbox>
                </span>
              </div>
           </template>
              <el-input type="text" v-model="content.telephone2" :disabled="(isOpen && !isAdmin) || (isOpen && isSecret) "></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8" :offset="4">
            <el-form-item :label="$t('calendar')" prop="calendarType"   >
              <el-select v-model="content.calendarType" :placeholder="$t('placeholder_select')" class="el-select-w" :disabled="(isOpen && !isAdmin) || (isOpen && isSecret)" @change="setCalendar">
                <el-option
                  v-for="cld in calendars"
                  :key="cld.id"
                  :label="cld.name"
                  :value="cld.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row class="labelSlot">
          <el-col :span="8">
            <el-form-item  >
              <template #label>
                <div class="df">
                <span class="greyColor">{{$t('email')}}</span>
                <span>
                  <span class="marginR10 greyColor">{{$t('public')}}</span>
                  <el-checkbox v-model="content.emailPublic" :disabled="(isOpen && !isAdmin) || (isOpen && isSecret)"></el-checkbox>
                </span>
              </div>
           </template>
              <el-input type="text" v-model="content.email"  :disabled="(isOpen && !isAdmin) || (isOpen && isSecret)"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8" :offset="4">
            <el-form-item :label="$t('orderByNo')"   >
              <el-input type="number" v-model="content.orderByNo" :disabled="(isOpen && !isAdmin) || (isOpen && isSecret)" onKeypress="return (/[\d\.]/.test(String.fromCharCode(event.keyCode)))"></el-input>
            </el-form-item>
          </el-col>
        </el-row></div>
        <div class="part" id="depUser">
        <p class="smallHeader">{{$t('dep_user')}}</p>
        <div class="role_card_wrap">
          <div class="role_card" v-for="item in deptRoleList" :key="item.id">
            <p class="role_header">
              <span class="header_left">
                <i class="iconfont icon-bq" aria-hidden="true"></i>
                <span class="marginL10 header_name">{{item.departmentName}}</span>
              </span>
              <el-dropdown size="small" v-if="!isAdmin">
                <span class="el-dropdown-link">
                  <i class="fa fa-ellipsis-v paddingT5" aria-hidden="true"></i>
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item @click.native='setDefaultDept(item.departmentId)' class="blueColor">{{$t('setDefault')}}</el-dropdown-item>
                  <template v-if="!((isOpen && isAdmin) || (isOpen && !isSecret))">
                    <el-dropdown-item @click.native="removeTab(item.departmentId)">{{$t('del')}}</el-dropdown-item>
                  </template>
                </el-dropdown-menu>
              </el-dropdown>
            </p>
            <div class="role_content">
              <div class="content_item" v-for="ite in item.applicationData" :key="ite.id">
                <p class="item_header">
                  <!-- <i class="fa fa-cube f20" aria-hidden="true"></i> -->
                  <span class="marginL20">{{ite.applicationName}}</span>
                  <!-- <span class="el-dropdown-link marginL20 smallDown">
                    <i class="el-icon-arrow-down el-icon--right"></i> 
                  </span> -->
                  <span class="marginL10 marginR10" v-if="!isAdmin">
                    <i class="el-icon-delete redColor" @click="delApplicationName(item.departmentId,ite.applicationId)"></i>
                  </span>
                </p>
                <div class="item_wrap">
                  <el-tag 
                    size="mini" 
                    class="marginL20"
                    v-for="tag in ite.roleData"
                    :key="tag.id"
                    >
                    <span class="role_tag">{{tag.roleName}}</span>
                    <template v-if="!((isOpen && isAdmin) || (isOpen && !isSecret))">
                      <i class="el-icon-close" @click="deleteRole(item.departmentId,ite.applicationId,tag.roleId)"></i>
                    </template>
                    </el-tag>
                </div>
              </div>
              <template v-if="!((isOpen && isAdmin) || (isOpen && !isSecret))">
                <el-button size="mini" class="add_role_btn" @click="setRole(item.departmentId)">
                  <i class="el-icon-plus" aria-hidden="true"></i>
                  {{$t('role_add')}}
                </el-button>
              </template>
            </div>
          </div>
          <div :class="'role_btn_wrap' + deptRoleList && deptRoleList.length>0 ? 'marginTop50':''" v-if="!(isAdmin)">
            <el-button size="small" @click="onAddRoleBtnClick(true, 'dept')">+{{$t('add_dept')}}</el-button>
          </div>
        </div></div>
        <div class="part" id="settingInfo">
        <p class="smallHeader">{{$t('settingInfo')}}</p>
        <el-row class="marginT18">
            <!-- <div class="d-inlineBlock" style="margin-right: 65px;"> -->
              <el-col :span="6" v-if="!((isOpen && isAdmin) || (isOpen && !isSecret))">
              <el-checkbox v-model="content.lockFlag" :disabled="(isOpen && isAdmin) || (isOpen && !isSecret)"></el-checkbox>
              <span class="marginL10 greyColor">{{$t('lockFlag')}}</span>
            <!-- </div> --></el-col>
            <!-- <div class="d-inlineBlock"  style="margin-right: 38px;"> -->
              <el-col :span="6" v-if="!((isOpen && isAdmin) || (isOpen && !isSecret))">
              <el-checkbox v-model="content.status" :disabled="(isOpen && isAdmin)|| (isOpen && !isSecret)"></el-checkbox>
              <span class="marginL10 greyColor">{{$t('status')}}</span>
            <!-- </div> --></el-col>
             <el-col :span="6">
                <el-checkbox :disabled="(isOpen && !isAdmin) || (isOpen && isSecret)" v-model="content.permissionType"></el-checkbox>
                <span class="marginL10 greyColor">{{$t('address_book')}}</span>
              <!-- </div> -->
              </el-col>
              <el-col :span="6">
              <!-- <div class="d-inlineBlock marginR10"> -->
                <el-checkbox v-model="content.showEmail"></el-checkbox>
                <span class="marginL10 greyColor">{{$t('open_email')}}</span>
              <!-- </div> -->
              </el-col>
        </el-row>
              <!-- <div class="d-inlineBlock marginR10"> -->
          <div class="userDept">
            <div  v-if="showDeptInterface" :style="`width:${content.liaisonOfficer?'50%':'25%'}`">
              <div class= "marginR10">
                <el-checkbox v-model="content.liaisonOfficer" :disabled="(isOpen && !isAdmin) || (isOpen && isSecret) "></el-checkbox>
                <span class="marginL10 greyColor">{{$t('liaisonOfficer')}}</span>
              </div>
              <div class=" mt-5" v-if="content.liaisonOfficer">
                <span class="marginR10 dept_text greyColor" >{{$t('inter_del')}}:</span>
                <el-select v-model="content.interfaceDepartmentList" :placeholder="$t('placeholder_select')" size="mini" class="w220">
                  <el-option label="" value=""></el-option>
                  <el-option
                    v-for="item in deptRoleList"
                    :key="item.departmentId"
                    :label="item.departmentName"
                    :value="item.departmentId">
                  </el-option>
                </el-select>
              </div>
            </div>
              <div v-if="showDeptUser">
                <div class="marginR10" :style="`width:${content.liaisonOfficer?'50%':'25%'}`">
                  <el-checkbox v-model="content.departmentUser" :disabled="(isOpen && !isAdmin) || (isOpen && isSecret)"></el-checkbox>
                  <span class="marginL10 greyColor">{{$t('domainUser')}}</span>
                </div>
                <div class=" mt-5" v-if="content.departmentUser">
                  <span class="marginR10 dept_text greyColor">{{$t('admin_del')}}:</span>
                  <span class="dept_wrap">
                    <span class="dept_tag">
                      <el-tag 
                        closable 
                        size="mini" 
                        class="marginR4"
                        v-for="item in content.manageDepartmentList"
                        :key="item.id"
                        @close="handleClose(item, 'man_dept')"
                      >{{item.name}}</el-tag>
                    </span>
                    <i class="iconfont icon-icon_bm_off" aria-hidden="true" @click="onAddRoleBtnClick(false, 'man_dept')"></i>
                  </span>
                </div>
              </div>
          </div>
         </div>
        <div class="part" id="proxySetting">
        <p class="smallHeader">{{$t('proxy_setting')}}</p>
        <el-row>
          <el-col :span="8">
            <el-form-item :label="$t('proxyUser')" >
              <el-input :value="content.proxyUser?content.proxyUser.name:''"
              :disabled="(isOpen && !isAdmin) || (isOpen && isSecret)"
              clearable :placeholder="$t('placeholder_select')" 
              @clear="onClearProxyUserBtn"
              :popper-append-to-body="false"
              class="width100">
              <template slot="append">
                <el-button @click="onProxyUserBtnClick"  class="chooseBtn" :disabled="(isOpen && !isAdmin) || (isOpen && isSecret)">
                <i class="el-icon-user"></i>
              </el-button>
              </template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="14" :offset="2">
            <el-form-item :label="$t('proxy_start_end_date')"   :required="!!(content.proxyUser&&content.proxyUser.name)">
              <el-date-picker
                :disabled="(isOpen && !isAdmin) || (isOpen && isSecret) || !haveProxy"
                v-model="content.startProxyTime"
                type="datetime"
                :placeholder="$t('datetime')"
                format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss"
                class="el-select-w width180"
              ></el-date-picker>
              <span class="marginL10 marginR10">~</span>
              <el-date-picker
                :disabled="(isOpen && !isAdmin) || (isOpen && isSecret) || !haveProxy"
                v-model="content.endProxyTime"
                type="datetime"
                :placeholder="$t('datetime')"
                format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss"
                class="width180"
              ></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row></div>
        <div class="part" id="moreSetting">
        <p class="smallHeader">{{$t('more_setting')}}</p>
        <el-row>
          <el-col :span="8">
            <el-form-item :label="$t('description')" >
              <el-input type="textarea" v-model="content.remarks" :disabled="(isOpen && !isAdmin) || (isOpen && isSecret)"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8" :offset="2" v-if="isOpen">
            <el-form-item :label="$t('SecuritySecret')" >
              <el-select v-model="content.secret" :placeholder="$t('placeholder_select')" :disabled="isAdmin">
                <el-option
                  v-for="item in secret"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        </div>
        <div  class="part" id="moreInfo">
        <!-- 更多信息 -->
        <p class="smallHeader" >{{$t('moreInfo')}}</p>
        <extend_flex 
          :contextPath="contextPath"
          :fieldextends="fieldextends"
          :content="content"
          v-if="fieldextends.length>0"
        />
        </div></div>
      </el-form>
    
    <role_select :visible.sync="setRoleVisiable" v-if="setRoleVisiable" :deptRoleList="changeDeptRoleList" />
    <user_selectbox :detail="paramcontent" :visible.sync="userSelectVisible" v-if="userSelectVisible" @select-ok="onSelectUserOk"  type="user" />
    <department_select 
      :visible.sync="departmentSelectVisible" 
      :invalid="invalid" 
      @select-ok="onSelectDepartmentOk" 
      :departments="deptRoleList"
      :isUserTree="true"
      :showDisbaleRoot="showDisbaleRoot"
      :showBox="false"
    />
    </div>
    </dialog_item>  
</template>

<script>
import { scrollHeight,processPassword } from '@/utils'
import { nameCheck, lengthCheck, checkHasId } from "@/utils/";
import role_select from "@/components/role_select.vue";
import extend_flex from "@/components/extendFlex.vue";
import user_selectbox from "@/components/user_selectbox.vue";
import department_select from "@/components/department_select.vue";
export default {
  components: {
    role_select,
    user_selectbox,
    department_select,
    extend_flex
  },
  props: {
    detail: Object,
    dialogTitle:String,
    visible:Boolean,
  },
  computed:{
    dialogVisible: {
      get() {
        return this.visible;
      },
      set(val) {
        this.$emit("update:visible", val);
      }
    }
  },
  data() {
    return {
      secret: [
        {
          id:'H1AXoh6qHwrdmc94WPD',
          name:'公开',
        },
        {
          id:'Y2Ieveh3RiMIEUfE2S9',
          name:'内部',
        },
        {
          id:'D3er2bQBVIukCalBw8y',
          name:'一般',
        },
        {
          id:'E490Xj47pjYvHCuQEZL',
          name:'重要',
        },
      ],
      scrollHeight: scrollHeight,
      contextPath:this.$api.getContextPath(),
      staticPath: this.$api.getStaticPath(),
      searchdata: {
        domainid: this.$route.query.domainid,
        departmentid: "",
        currpage: 1,
        pagelines: 20,
        orderby: "",
        data:{
          name: "",
          loginno: "",
          superiorname: "",
          roleid: "",
        }
      },
      content: {}, //部门信息对象
      userSelectVisible: false,
      currentEditField: "", //PROXY
      calendars: [], //用户可用的工作日历
      tableData: [],
      showmode: "LIST", //LIST 或 DETAIL，默认为LIST
      tabIndex:0,
      editableTabs:[],
      editableTabsValue:"",
      departmentSelectVisible:false,
      addDept:{},
      departments:[],
      kmRole:[],
      imgBase:'',
      kmData:[
        {
            "id": "0001",
            "levels": 0,
            "name": this.$t('staff')
        },
        {
            "id": "0010",
            "levels": 10,
            "name": this.$t('dept_know_manager')
        },
        {
            "id": "0020",
            "levels": 20,
            "name": this.$t('committee_know_manager')
        },
        {
            "id": "0100",
            "levels": 10,
            "name": this.$t('enterprise_know_manager')
        }
      ],
      km5Data:[
        {
            "id": "KMNORMALROLEID",
            "levels": 0,
            "name": this.$t('staff')
        },
        {
            "id": "KMDEPTADMINROLEID",
            "levels": 10,
            "name": this.$t('dept_know_manager')
        },
        {
            "id": "KMCOMMITTEEADMINROLEID",
            "levels": 20,
            "name": this.$t('committee_know_manager')
        },
        {
            "id": "KMSUPERADMINROLEID",
            "levels": 10,
            "name": this.$t('enterprise_know_manager')
        }
      ],
      kmCheckRole:[],
      rules:{
        name:[
          {required: true, message: this.$t('username_required'), trigger: 'blur'},
          { validator: lengthCheck, trigger: "blur" },
        ],
        loginno:[
          {required: true, message: this.$t('account_required'), trigger: 'blur'},
          { validator: lengthCheck, trigger: "blur" },
        ],
        loginpwd:[
          {required: true, message:  this.$t('password_required'), trigger: 'blur'},
        ],
        confirmpwd:[
          {required: true, message:  this.$t('confirm_password_required'), trigger: 'blur'},
        ],
        calendarType:[
          {required: true, message:  this.$t('calendar_required'), trigger: 'change'},
        ],
        dept:[
          {required: true, message: this.$t('department_required'), trigger: 'blur'},
        ]
      },
      fieldextends:[],
      first:true,
      pwdPre:"",
      password:"888888qqqq",
      dialogImageUrl: '',
      invalid:true,
      options:[],
      radioValue:'',
      selectValue:'',
      paramcontent: {},
      customApps:[],
      customAppsRole:[],
      defaultRole:[],
      haveProxy:false,
      isAllRight:true,
      setRoleVisiable:false,
      deptRoleList:[],
      changeDeptRoleList:[],
      isOpen:false,//开关是否开启
      isAdmin:false,//是否是系统管理员
      isSecret:false,//是否是安全保密员
      activeNames: [], // 默认展开的树
      btnLoading: false, // 按钮的加载中
      showDisbaleRoot: false, // 部门树的最高点是否要禁用
      whichDept: '', // 点击的是哪个部门按钮
      showDeptInterface: false, // 是否显示部门接口人
      showDeptUser: false, // 是否显示部门管理员
      loginnoFlag:false,//记录账号状态
      activeName:'baseInfo',
      btnDialogArr:[],
      isnewUser:false,//新建用户
    };
  },
  created() {
    let tempArr=[]
    if(this.$store.state.currentUser.isOpenSecurity) {
      this.isOpen=true;
      if (this.$store.state.currentUser.type == 'admin') {
        this.isAdmin = true;//是否是系统管理员
      }else if (this.$store.state.currentUser.type == 'secret') {
        this.isSecret= true;//是否是系统管理员
      }
    }else{
      this.isOpen=false;
    }
    //目前先把不同身份登录的校验去掉，如果需要加上，直接把下面一行代码去掉即可
    // if(this.isOpen&&this.detail&& this.detail.id) this.isOpen=true
    // else this.isOpen=false
    
    

    let that=this;
    this.getCustomApp();
    // 增加一个确认密码项
    if(!this.detail.confirmpwd)
      this.detail.confirmpwd = ''
    this.content=JSON.parse(JSON.stringify(this.detail));
    if(this.content.proxyUser){
      this.haveProxy=true;
    }else{
      this.haveProxy=false;
    }
    this.content.startProxyTime= this.content.startProxyTime? this.resolvingDate(this.content.startProxyTime):"";
    this.content.endProxyTime= this.content.startProxyTime? this.resolvingDate(this.content.endProxyTime):"";
    this.content.status=this.content.status == true? true : false
    this.content.permissionType=this.content.permissionType=='public'? true : false;
    this.pwdPre=this.content.loginpwd;
    this.content.confirmpwd = this.content.loginpwd;
    this.content.manageDepartmentList = this.content.manageDepartmentList ? this.content.manageDepartmentList : [];
    this.content.interfaceDepartmentList = this.content.interfaceDepartments ? eval(this.content.interfaceDepartments)[0] : "";
    //数据没有变化
    this.$set(this.content,"lockFlag",this.content.lockFlag == 0?true : false)
    if(this.content.id){
      this.getKmRole();
    }
    // 如果选项内容切换，那么需要清空原来的数据
    let flag = false
    //请求字段扩展数据
    // this.getFieldExtends()
    this.getCalendars();
    //传给子组件user_select的参数
    this.paramcontent.domainsId = this.$route.query.domainid;
    this.paramcontent.customAppsId = "";
    this.paramcontent.tabVisible = false;
    //this.searchTableData();
    // 判断是否显示部门接口人和部门管理员
    if(sessionStorage.getItem('domainData')){
      let obj = JSON.parse(sessionStorage.getItem('domainData'))
      // 登陆用户是超级管理员和或域管理员时显示部门管理员
      if(obj.loginType == 'super' || obj.loginType == 'domain'){
        this.showDeptUser = true
      }
      // 登陆的用户是超级管理员或域管理员或部门管理员时显示部门接口人
      if(obj.loginType == 'super' || obj.loginType == 'domain' || this.content.departmentUser){
        this.showDeptInterface = true
      }else{
        this.showDeptInterface = false
      }
    }
    this.loginnoFlag=!!(this.detail && this.detail.loginno)
    tempArr=[{label:this.$t('cancel'),type:'plain',name:'cancel'},{label:this.$t('saveAndNew'),name:'saveAndNew'},{label:this.$t('save'),name:'save'}]
    if(this.isSecret){
      tempArr.splice(1,1)
    }
    this.btnDialogArr=[...tempArr]
    if(!this.content.name) {
      this.isnewUser = true
      if(this.isAdmin) {
        this.content.secret = 'H1AXoh6qHwrdmc94WPD' //系统管理员新建用户默认公开
      }
    }
 },
  mounted(){
  },
  methods: {
    onBtnDialogClick(name){
      if(name=='saveAndNew'){this.onSaveBtnClick('new')}
      else if(name=='save'){this.onSaveBtnClick('no')}
    },
    getScroll(event){
      let scrollBarTop = event.target.scrollTop,scrollBarHeight=event.target.scrollHeight,percentage=0;
      console.log('event.target.scrollHeight--->:',scrollBarTop,event.target.scrollHeight,event.target.clientHeight)
      for(let i=0;i<6;i++){
          let offsetTop=(document.getElementsByClassName('part')[i].offsetTop)-105;
          let scrollHeight = document.getElementsByClassName('part')[i].scrollHeight;
          //在等比例 高度/总高度    滚动条/总体高度(未完成)
          if (scrollBarTop >= offsetTop && scrollBarTop<=(offsetTop+scrollHeight)) {
            if(i==0){
              this.activeName='baseInfo'
            }else if(i==1){
              this.activeName='depUser'
            }else if(i==2){
              this.activeName='settingInfo'
            }else if(i==3){
              this.activeName='proxySetting'
            }else if(i==4){
              this.activeName='moreSetting'
            }else{
              this.activeName='moreInfo'
            }
          }
      }
    },
    getFieldExtends(){
      let that=this
     let dataJson={ 
      currpage:1,
      pagelines:999,
      data:{
        type:"",
        fortable:"tableUser",
        domainid: this.$route.query.domainid,
        belong:"All"
      }
    };
    this.$api.getFieldExtends(
        dataJson,
      {
        onSucess: resp => {
          resp.data.data.datas.forEach( elm => {
            if(elm.type == "radio" || elm.type == "select" || elm.type == "checkbox"){
              let option = elm.options.split(";");
              let arr = [];
              if(elm.type == "radio" || elm.type == "select"){
                for(let i=0;i<option.length;i++){
                  let obj = {}
                  obj.label = option[i];
                  obj.value = option[i];
                  arr.push(obj);
                }
                elm.options = arr;
              }else if(elm.type == "checkbox"){
                if(this.content[elm.name])  {elm.checkboxList = this.content[elm.name].split(";")}
                else elm.checkboxList=[]
                elm.options = option;
              }
            }else if(elm.type == "address") {
              let arr = [];
              if(this.content[elm.name]){
                 this.content[elm.name+'_registerAddress'] = this.content[elm.name].split(',')[3];
                 arr.push(this.content[elm.name].split(',')[0],this.content[elm.name].split(',')[1],this.content[elm.name].split(',')[2])
              }
              this.content[elm.name] = arr;
            }
            that.fieldextends.push(elm)
            // 遍历查找看是否有对应的值
            if(that.fieldextends[that.fieldextends.length] ){
              that.content[elm.name] = checkHasId(that.fieldextends[that.fieldextends.length].options, that.content[elm.name], 'label')
            }
          })
        }
      }
    );
    },
    getCalendars(){
      debugger
      this.$api.getCalendars(
        { currpage: "", pagelines: ""},
        {
          onSucess: resp => {
            this.calendars = resp.data.data.datas;
            if(this.content.calendarType=="" || !this.content.calendarType){
              this.calendars.forEach(elm=>{
                if(elm.name=="标准日历"){
                  // this.content.calendarType=elm.id;
                    this.$set(this.content, 'calendarType', elm.id)
                }
              })
            }
          }
        }
      );
    },
    setCalendar(val){
      this.$set(this.content, 'calendarType', val)
      this.$forceUpdate()
    },
    /**
     * 账号失去焦点
     */
    handleBlur(){
      let loginNo = this.content.loginno;
      if(loginNo && this.detail.isCreate){
        this.$api.getLoginNo({ domainid: this.$route.query.domainid , loginNo},{
          onSucess: resp => {
            let data = resp.data;
            if(data.errcode == 0 && data.data){
              this.$confirm("此账号已经在企业域（某个）存在，是否将手机、密码，邮箱带过来").then(()=>{
                let content = {
                  ...this.content,
                  ...data.data,
                  confirmpwd: data.data.loginpwd
                }
                this.content = content;
              }).catch(() => {});
            }
          }
        });
      }
    },
    getCustomApp(){
      let that=this;
      this.$api.getCustomAppConfig(
        { data:{name: ""} },
        {
          onSucess: resp => {
            this.customApps = resp.data.data.datas;
            
            for (let i = 0; i < this.customApps.length; i++) {
            this.$api.getRoleList(
              { applicationid: this.customApps[i].id ,pagelines:10000},
              {
                onSucess: resp => {
                  this.customApps[i].roleList = resp.data.data.role;
                  resp.data.data.role.forEach(elm=>{
                    //默认角色的获取，勿删
                    if(elm.defaultRole){
                      let val={ roleId: elm.roleId,roleName:elm.roleName, applicationId: that.customApps[i].id, departmentId:"" }
                      that.defaultRole.push(val)
                    }
                  })
                  that.$forceUpdate();
                }
              }
            );
          }
          }
        }
      )
    },
    getKmRole(){
      this.$api.getDeptUser(
        this.content.id,
        {
          onSucess: resp => {
            this.deptRoleList=resp.data.data.departmentdata;
            // 判断有没有默认的部门
            let flag = false
            if(this.deptRoleList.length>0){
              for(let i=0;i<this.deptRoleList.length;i++){
                if(this.content.defaultDepartment==this.deptRoleList[i].departmentId){
                  this.deptRoleList[i].departmentName +="(默认)"
                  flag = true
                }
                this.editableTabsValue=this.deptRoleList[i].departmentId;
                this.deptRoleList[i].title=this.deptRoleList[i].departmentName;
              }
            }
            if(!flag && this.deptRoleList[0]){
              this.deptRoleList[0].departmentName +="(默认)"
            }
            resp.data.data.kmdata.forEach(elm=>{
              this.kmCheckRole.push(elm.id);
              
            })
          }
        }
      );
    },
    //转换参数的日期格式
    resolvingDate(date){
      let d = new Date(date);

      let month = (d.getMonth() + 1) < 10 ? '0'+(d.getMonth() + 1) : (d.getMonth() + 1);
      let day = d.getDate()<10 ? '0'+d.getDate() : d.getDate();
      let hours = d.getHours()<10 ? '0'+d.getHours() : d.getHours();
      let min = d.getMinutes()<10 ? '0'+d.getMinutes() : d.getMinutes();
      let sec = d.getSeconds()<10 ? '0'+d.getSeconds() : d.getSeconds();

      let times=d.getFullYear() + '-' + month + '-' + day + ' ' + hours + ':' + min + ':' + sec;

      return times
    },
    
    onNodeClick(dept) {
      this.searchdata.departmentid = dept.id;
      this.searchTableData();
    },
    
    onProxyUserBtnClick() {
      this.currentEditField = "proxyUser";
      this.userSelectVisible = true;
    },

    onSuperiorUserBtnClick() {
      this.currentEditField = "superior";
      this.userSelectVisible = true;
    },

    onAddRoleBtnClick(val, dept){
      this.showDisbaleRoot = val;
      this.whichDept = dept;
      this.departmentSelectVisible=true;
    },

    onSelectUserOk(users) {
      if (users && users.length > 0) {
        if(this.currentEditField=="proxyUser"){
          this.haveProxy=true;
          this.$forceUpdate();
        }
        this.content[this.currentEditField] = users[0];
      }else if(users && users.length == 0){
        this.content[this.currentEditField]=null;
      }
    },

    onSelectDepartmentOk(role){
      if(this.whichDept == 'dept'){
        let that=this;
        let length=that.deptRoleList.length;
        let have=false;
        for(let j=0;j<that.deptRoleList.length;j++){
          if(that.deptRoleList[j].departmentId==role.id){
            have=true;
            break;
          }
        }
        if(!have){
          this.addDept=role;
          this.addTab();
        }
        if(length==0  && !this.content.defaultDepartment){
          this.setDefaultDept(role.id)
        }
      }else if(this.whichDept == 'man_dept'){ // 管理部门
        // 去重
        let mFlag = false
        for(let j=0;j<this.content.manageDepartmentList.length;j++){
          if(this.content.manageDepartmentList[j].id==role.id){
            mFlag=true;
            break;
          }
        }
        if(!mFlag){
          this.content.manageDepartmentList.push(role)
        }
      }
    },

    handleClose(tag, val){
      let index = ''
      if(val == 'man_dept'){
        for(let j=0;j<this.content.manageDepartmentList.length;j++){
          if(this.content.manageDepartmentList[j].id==tag.id){
            index = j
            break;
          }
        }
        this.content.manageDepartmentList.splice(index, 1)
      }
      this.$forceUpdate()
    },

    encodeUTF8(s) {
      let i, r = [], c, x;
      for (i = 0; i < s.length; i++)
        if ((c = s.charCodeAt(i)) < 0x80) r.push(c);
        else if (c < 0x800) r.push(0xC0 + (c >> 6 & 0x1F), 0x80 + (c & 0x3F));
        else {
          if ((x = c ^ 0xD800) >> 10 == 0) //对四字节UTF-16转换为Unicode
            c = (x << 10) + (s.charCodeAt(++i) ^ 0xDC00) + 0x10000,
              r.push(0xF0 + (c >> 18 & 0x7), 0x80 + (c >> 12 & 0x3F));
          else r.push(0xE0 + (c >> 12 & 0xF));
          r.push(0x80 + (c >> 6 & 0x3F), 0x80 + (c & 0x3F));
        };
      return r;
    },

    // 字符串加密成 hex 字符串
    sha1(s) {
      var data = new Uint8Array(encodeUTF8(s))
      var i, j, t;
      var l = ((data.length + 8) >>> 6 << 4) + 16, s = new Uint8Array(l << 2);
      s.set(new Uint8Array(data.buffer)), s = new Uint32Array(s.buffer);
      for (t = new DataView(s.buffer), i = 0; i < l; i++)s[i] = t.getUint32(i << 2);
      s[data.length >> 2] |= 0x80 << (24 - (data.length & 3) * 8);
      s[l - 1] = data.length << 3;
      var w = [], f = [
         function () { return m[1] & m[2] | ~m[1] & m[3]; },
         function () { return m[1] ^ m[2] ^ m[3]; },
         function () { return m[1] & m[2] | m[1] & m[3] | m[2] & m[3]; },
         function () { return m[1] ^ m[2] ^ m[3]; }
        ], rol = function (n, c) { return n << c | n >>> (32 - c); },
        k = [1518500249, 1859775393, -1894007588, -899497514],
        m = [1732584193, -271733879, null, null, -1009589776];
      m[2] = ~m[0], m[3] = ~m[1];
      for (i = 0; i < s.length; i += 16) {
        var o = m.slice(0);
        for (j = 0; j < 80; j++)
          w[j] = j < 16 ? s[i + j] : rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1),
            t = rol(m[0], 5) + f[j / 20 | 0]() + m[4] + w[j] + k[j / 20 | 0] | 0,
            m[1] = rol(m[1], 30), m.pop(), m.unshift(t);
        for (j = 0; j < 5; j++)m[j] = m[j] + o[j] | 0;
      };
      t = new DataView(new Uint32Array(m).buffer);
      for (var i = 0; i < 5; i++)m[i] = t.getUint32(i << 2);

      var hex = Array.prototype.map.call(new Uint8Array(new Uint32Array(m).buffer), function (e) {
        return (e < 16 ? "0" : "") + e.toString(16);
      }).join("");
      return hex;
    },

    changePwd(val){
      if(val!==this.pwdPre && val!="" && val){
        this.password="";
      }else{
        //如果新密码为空，也要设置为初始
        this.password="888888qqqq";
      }
    },

    // 手机号正则
    phoneReg(tel){
      const DLreg = /^((\+?86)|(\(\+86\)))?[1][3,4,5,6,7,8,9][0-9]{9}$/;
      const HKreg = /^((\+?852)|(\(\+852\)))([5|6|8|9])\d{7}$/;
      const AMreg = /^[0][9]\d{8}$/;
      return (DLreg.test(tel) || HKreg.test(tel) || AMreg.test(tel))
    },
    //保存
    onSaveBtnClick(type) {
      debugger
      let password=''
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.isAllRight = true;
          if (
            this.content.name &&
            !/^[\u4e00-\u9fa5_·a-zA-Z0-9.\s]+$/g.test(this.content.name) //数字字母汉字下划线中间点
          ) {
            this.$message({
              showClose: true,
              message: this.$t("msg_special_char"),
              type: "error",
            });
            this.isAllRight = false;
            return false;
          }
          if (parseInt(this.content.orderByNo) < 0) {
            this.$message({
              showClose: true,
              message: this.$t("msg_orderno_negative"),
              type: "error",
            });
            this.isAllRight = false;
            return false;
          }else if (this.content.orderByNo > 2147483647) {
            this.$message({
              showClose: true,
              message: "请输入0-2147483647的数字",
              type: "error",
            });
            this.isAllRight = false;
            return false;
          }
          if (this.content.telephone && !this.phoneReg(this.content.telephone) || this.content.telephone2 &&
            !this.phoneReg(this.content.telephone2)) {
            this.$message({
              showClose: true,
              message: "手机号输入有误",
              type: "error",
            });
            this.isAllRight = false;
            return false;
          }
          if (
            this.content.email &&
            !/^[a-zA-Z0-9_-]+(\+?.[a-zA-Z0-9_-]+)+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(
              this.content.email
            )
          ) {
            this.$message({
              showClose: true,
              message: this.$t("msg_email_incorrectly"),
              type: "error",
            });
            this.isAllRight = false;
            return false;
          }
          this.calendars.forEach((elm) => {
            if (elm.id == this.content.calendarType) {
              this.content.calendarTypeName = elm.name;
            }
          });
          // 判断当前项是否为必填项
          let checkArr = [];
          let checkTip = "";
          let have = true;
          if (this.fieldextends.length > 0) {
            this.fieldextends.map((item) => {
              if (item.isNotNull) {
                checkArr.push(item);
              }
              if (item.type == "address") {
                this.content[item.name];
                if (this.content[item.name + "_registerAddress"]) {
                  if (typeof this.content[item.name] == "string") {
                    this.content[item.name] =
                      this.content[item.name] +
                      "," +
                      this.content[item.name + "_registerAddress"];
                  } else {
                    this.content[item.name].push(
                      this.content[item.name + "_registerAddress"]
                    );
                  }
                }
                this.content[item.name] = this.content[item.name].toString();
              }
            });
            if (checkArr.length > 0) {
              checkArr.some((ele) => {
                if (!this.content[ele.name]) {
                  have = false;
                  checkTip += ele.label + ",";
                } else if (ele.type == "address") {
                  if (typeof this.content[ele.name] == "object") {
                    if (!this.content[ele.name][0]) {
                      have = false;
                      checkTip += ele.label + ",";
                    }
                  } else if (typeof (this.content[ele.name] == "string")) {
                    if (!this.content[ele.name].replace(/\,/g, "")) {
                      have = false;
                      checkTip += ele.label + ",";
                    }
                  }
                }
              });
            }
            if (!have) {
              this.$message.error(
                checkTip.substring(0, checkTip.lastIndexOf(",")) +
                  "字段为必填项"
              );
              return false;
            }
          }
          this.content.roleDepartments = [];
          for (let j = 0; j < this.deptRoleList.length; j++) {
            let obj = {
              id: this.deptRoleList[j].departmentId,
              name: this.deptRoleList[j].departmentName,
            };
            this.departments.push(obj);
            for (
              let k = 0;
              k < this.deptRoleList[j].applicationData.length;
              k++
            ) {
              for (
                let l = 0;
                l < this.deptRoleList[j].applicationData[k].roleData.length;
                l++
              ) {
                let deptRole = {
                  roleId: "",
                  departmentId: "",
                  applicationId: "",
                  isDefaultDepartment: "",
                };
                deptRole.departmentId = this.deptRoleList[j].departmentId;
                deptRole.applicationId =
                  this.deptRoleList[j].applicationData[k].applicationId;
                deptRole.roleId =
                  this.deptRoleList[j].applicationData[k].roleData[l].roleId;
                if (
                  this.deptRoleList[j].departmentId ==
                  this.content.defaultDepartment
                ) {
                  deptRole.isDefaultDepartment = "true";
                } else {
                  deptRole.isDefaultDepartment = "false";
                }
                this.content.roleDepartments.push(deptRole);
              }
            }
          }
          if (this.customApps.length == 0) {
            //域(租户)没有绑定软件，不需要校验软件角色
            if (this.departments.length == 0) {
              //没有选择部门
              this.$message({
                showClose: true,
                message: this.$t("msg_select_dept"),
                type: "error",
              });
              this.isAllRight = false;
              return false;
            }
          } else {
            //绑定软件了
            if(!(this.isAdmin && this.isnewUser)) { //安全开关开启后，系统管理员sysadmin，新建用户可以不选部门保存成功
              if (this.departments.length == 0) {
                //没有选择部门
                this.$message({
                  showClose: true,
                  message: this.$t("msg_select_dept"),
                  type: "error",
                });
                this.isAllRight = false;
                return false;
              }
              if (
                !this.content.roleDepartments ||
                this.content.roleDepartments.length == 0
              ) {
                //如果选择了部门没有选择角色
                this.$message({
                  showClose: true,
                  message: this.$t("msg_select_role"),
                  type: "error",
                });
                this.isAllRight = false;
                return false;
              }
            }
            //检查部门&角色中的应用中的角色是否存在
            this.deptRoleList.forEach((depItem) => {
              let flagTemp = depItem.applicationData.some((depAppItem) => {
                return depAppItem.roleData.length != 0;
              });
              if (!flagTemp) {
                this.$message({
                  showClose: true,
                  message: this.$t("msg_select_role"),
                  type: "error",
                });
                this.isAllRight = false;
                return false;
              }
            });
            if (this.isAllRight == false) {
              return false;
            }
          }
          if (!!(this.content.proxyUser && this.content.proxyUser.name)) {
            if (!this.content.startProxyTime && !this.content.endProxyTime) {
              this.$message({
                showClose: true,
                message: this.$t("msg_agency_start_end_date"),
                type: "error",
              });
              return false;
            }
            if (!this.content.startProxyTime && this.content.endProxyTime) {
              this.$message({
                showClose: true,
                message: this.$t("msg_startProxyTime"),
                type: "error",
              });
              return false;
            }
            if (this.content.startProxyTime && !this.content.endProxyTime) {
              this.$message({
                showClose: true,
                message: this.$t("msg_endProxyTime"),
                type: "error",
              });
              return false;
            }
          }
          if (
            this.content.roleDepartments.length == 0 &&
            this.departments.length != 0
          ) {
            this.content.roleDepartments = [];
            this.departments.forEach((elm) => {
              this.content.roleDepartments.push({
                roleId: "",
                applicationId: "",
                departmentId: elm.id,
              });
            });
          }
          if(!(this.isAdmin && this.isnewUser)) {
            if (
              this.content.defaultDepartment == "" ||
              !this.content.defaultDepartment
            ) {
              this.$message({
                showClose: true,
                message: this.$t("msg_default_dept"),
                type: "error",
              });
              this.isAllRight = false;
              return false;
            }
          }
          if (this.password != "888888qqqq" && this.content.loginpwd) {
            // 判断确认密码与密码是否一致
            if (this.content.loginpwd != this.content.confirmpwd) {
              this.$message.error(this.$t('msg_confirm_password_not_same'));
              this.isAllRight = false;
              return false;
            }
            //更改密码，且新密码不为空
            this.pwdPre = this.content.loginpwd;
            // this.content.loginpwd = this.processPassword(this.content.loginpwd);
            password=processPassword(this.content.loginpwd);
          } else if (
            this.password == "888888qqqq" &&
            (this.content.loginpwd == "" || !this.content.loginpwd)
          ) {
            //用户密码为空或者没有改变
            this.$message({
              showClose: true,
              message: this.$t("msg_require_password"),
              type: "error",
            });
            this.isAllRight = false;
            return false;
          } else {
            this.content.loginpwd = "888888qqqq";
            password=this.content.loginpwd
            if (!this.content.confirmpwd) {
              return false;
            }
          }
          let contentSub = {
            avatar: this.content.avatar,
            name: this.content.name,
            loginno: this.content.loginno,
            departmentUser: false,
            loginpwd: "123456",
            email: "email@teemlink.com",
            emailPublic: true,
            telephone: "13192286346",
            telephonePublic: true,
            calendarType: "i7xj207zBMEwBp8aATE",
            calendarTypeName: "夜班日历",
            telephone2: "13192286349",
            telephonePublic2: true,
            reportTree: "",
            superiorid: "",
            allUsers: "",
            _proxyUser: "",
            remarks: "1111",
            secret:'',
            startProxyTime: "2019-09-30 16:41:01",
            endProxyTime: "2019-10-11 16:41:04",
            permissionType: true,
            showEmail: false,
            orderByNo: 0,
            lockFlag: false,
            status: true,
            interfaceDepartments: "",
            manageDepartments: "",
            defaultDepartment: "Z42xU8LmniRouZ93E7s",
            _userRoleDepartmentJson:
              '[{"roleId":"kPLbeydkgiYW6NIkCt0","departmentId":"Z42xU8LmniRouZ93E7s","applicationId":"HdPeBqYwJyFyjHkhZu3","isDefaultDepartment":"true"}]',
            _userKMRoleJson: '["0001"]',
          };
          if (this.content && this.content.id) {
            contentSub.id = "";
            contentSub = {
              avatar: this.content.avatar,
              id: this.content.id,
              name: this.content.name,
              departmentUser: this.content.departmentUser,
              ddUserId: this.content.ddUserId ? this.content.ddUserId : "",
              fsUserId: this.content.fsUserId ? this.content.fsUserId : "",
              loginno: this.content.loginno,
              loginpwd: password, //this.content.loginpwd
              email: this.content.email ? this.content.email : "",
              emailPublic: this.content.emailPublic,
              telephone: this.content.telephone ? this.content.telephone : "",
              telephonePublic: this.content.telephonePublic,
              calendarType: this.content.calendarType,
              calendarTypeName: this.content.calendarTypeName,
              telephone2: this.content.telephone2
                ? this.content.telephone2
                : "",
              telephonePublic2: this.content.telephonePublic2,
              reportTree: "",
              superiorid: this.content.superior ? this.content.superior.id : "",
              allUsers: "",
              liaisonOfficer: this.content.liaisonOfficer
                ? this.content.liaisonOfficer
                : false,
              superAdmin: this.content.superAdmin
                ? this.content.superAdmin
                : false,
              _proxyUser: this.content.proxyUser
                ? this.content.proxyUser.id
                : "",
              remarks: this.content.remarks ? this.content.remarks : "",
              secret: this.content.secret ? this.content.secret : "",
              startProxyTime: this.content.startProxyTime
                ? this.content.startProxyTime
                : "",
              endProxyTime: this.content.endProxyTime
                ? this.content.endProxyTime
                : "",
              permissionType:
                this.content.permissionType == true ? "public" : "private",
              orderByNo: this.content.orderByNo
                ? parseInt(this.content.orderByNo)
                : 0,
              lockFlag: this.content.lockFlag == true ? 0 : 1,
              status: this.content.status == true ? 1 : 0,
              showEmail: this.content.showEmail
                ? this.content.showEmail
                : false,
              interfaceDepartments: JSON.stringify([
                this.content.interfaceDepartmentList,
              ]),
              manageDepartments: this.content.manageDepartmentList
                ? this.content.manageDepartmentList
                    .map((item) => item.id)
                    .join(",")
                : "",
              defaultDepartment: this.content.defaultDepartment
                ? this.content.defaultDepartment
                : "",
              _userRoleDepartmentJson: this.content.roleDepartments
                ? JSON.stringify(this.content.roleDepartments).replace(
                    /"/g,
                    "'"
                  )
                : "",
              _userKMRoleJson: JSON.stringify(this.kmCheckRole).replace(
                /"/g,
                "'"
              )
                ? JSON.stringify(this.kmCheckRole).replace(/"/g, "'")
                : "",
              field1: this.content.field1 ? this.content.field1 : "",
              field2: this.content.field2 ? this.content.field2 : "",
              field3: this.content.field3 ? this.content.field3 : "",
              field4: this.content.field4 ? this.content.field4 : "",
              field5: this.content.field5 ? this.content.field5 : "",
              field6: this.content.field6 ? this.content.field6 : "",
              field7: this.content.field7 ? this.content.field7 : "",
              field8: this.content.field8 ? this.content.field8 : "",
              field9: this.content.field9 ? this.content.field9 : "",
              field10: this.content.field10 ? this.content.field10 : "",
              field11: this.content.field11 ? this.content.field11 : "",
              field12: this.content.field12 ? this.content.field12 : "",
              field13: this.content.field13 ? this.content.field13 : "",
              field14: this.content.field14 ? this.content.field14 : "",
              field15: this.content.field15 ? this.content.field15 : "",
              field16: this.content.field16 ? this.content.field16 : "",
              field17: this.content.field17 ? this.content.field17 : "",
              field18: this.content.field18 ? this.content.field18 : "",
              field19: this.content.field19 ? this.content.field19 : "",
              field20: this.content.field20 ? this.content.field20 : "",
              field21: this.content.field21 ? this.content.field21 : "",
              field22: this.content.field22 ? this.content.field22 : "",
              field23: this.content.field23 ? this.content.field23 : "",
              field24: this.content.field24 ? this.content.field24 : "",
              field25: this.content.field25 ? this.content.field25 : "",
            };
            this.btnLoading = true;
            this.$api.getLoginNo(
              {
                loginNo: contentSub.loginno,
              },
              {
                onSucess: (resp) => {
                  let data = resp.data;
                  let isSyncUser = false;
                  if (data.errcode == 0 && data.data) {
                    isSyncUser = confirm(
                      "此账号已经在其他域已存在，是否将手机、密码，邮箱覆盖到其余域xx（某个)"
                    );
                  }
                  this.$api.updateUser(
                    {
                      userid: this.content.id,
                      isSyncUser,
                      data: contentSub,
                    },
                    {
                      onSucess: (resp) => {
                        this.btnLoading = false;
                        if (resp.data.errcode == 0) {
                          this.$message({
                            showClose: true,
                            message: this.$t("msg_save_success"),
                            type: "success",
                          });
                          this.password = "888888qqqq";
                          if (type == "back") {
                            this.$emit("exit");
                          } else if (type == "new") {
                            this.content = {
                              startProxyTime: "",
                              endProxyTime: "",
                              status: 1,
                              permissionType: "public",
                              roleDepartments: [],
                              departmentUser: false,
                            };
                            this.content.status =
                              this.content.status == true ? true : false;
                            this.content.permissionType =
                              this.content.permissionType == "public"
                                ? true
                                : false;
                            this.content.showEmail = false;
                            this.departments = [];
                            this.kmCheckRole = [];
                            this.deptRoleList = [];
                            this.fieldextends=[];
                            //请求字段扩展数据
                            // this.getFieldExtends()
                            this.getCalendars();
                            this.pwdPre = "";
                            this.loginnoFlag=false
                          } else {
                            this.$emit("refresh");
                          }
                        } else {
                          this.content.loginpwd = this.pwdPre;
                          this.$message({
                            showClose: true,
                            message: resp.data.errmsg,
                            type: "error",
                          });
                        }
                      },
                    }
                  );
                },
              }
            );
          } else {
            //新建
            contentSub = {
              avatar: this.content.avatar,
              name: this.content.name,
              loginno: this.content.loginno,
              loginpwd: password, //this.content.loginpwd
              departmentUser: this.content.departmentUser,
              email: this.content.email ? this.content.email : "",
              emailPublic: this.content.emailPublic?this.content.emailPublic:false,
              telephone: this.content.telephone ? this.content.telephone : "",
              telephonePublic: this.content.telephonePublic?this.content.telephonePublic:false,
              calendarType: this.content.calendarType,
              calendarTypeName: this.content.calendarTypeName,
              telephone2: this.content.telephone2
                ? this.content.telephone2
                : "",
              telephonePublic2: this.content.telephonePublic2?this.content.telephonePublic2:false,
              reportTree: "",
              superiorid: this.content.superior ? this.content.superior.id : "",
              allUsers: "",
              _proxyUser: this.content.proxyUser
                ? this.content.proxyUser.id
                : "",
              remarks: this.content.remarks ? this.content.remarks : "",
              secret: this.content.secret ? this.content.secret : "",
              startProxyTime: this.content.startProxyTime
                ? this.content.startProxyTime
                : "",
              endProxyTime: this.content.endProxyTime
                ? this.content.endProxyTime
                : "",
              permissionType:
                this.content.permissionType == true ? "public" : "private",
              orderByNo: this.content.orderByNo
                ? parseInt(this.content.orderByNo)
                : 0,
              lockFlag: this.content.lockFlag == true ? 0 : 1,
              status: this.content.status == true ? 1 : 0,
              showEmail: this.content.showEmail == true ? true : false,
              defaultDepartment: this.content.defaultDepartment
                ? this.content.defaultDepartment
                : "",
              interfaceDepartments: JSON.stringify([
                this.content.interfaceDepartmentList,
              ]),
              manageDepartments: this.content.manageDepartmentList
                ? this.content.manageDepartmentList
                    .map((item) => item.id)
                    .join(",")
                : "",
              _userRoleDepartmentJson: this.content.roleDepartments
                ? JSON.stringify(this.content.roleDepartments).replace(
                    /"/g,
                    "'"
                  )
                : "",
              _userKMRoleJson: JSON.stringify(this.kmCheckRole).replace(
                /"/g,
                "'"
              )
                ? JSON.stringify(this.kmCheckRole).replace(/"/g, "'")
                : "",
              field1: this.content.field1 ? this.content.field1 : "",
              field2: this.content.field2 ? this.content.field2 : "",
              field3: this.content.field3 ? this.content.field3 : "",
              field4: this.content.field4 ? this.content.field4 : "",
              field5: this.content.field5 ? this.content.field5 : "",
              field6: this.content.field6 ? this.content.field6 : "",
              field7: this.content.field7 ? this.content.field7 : "",
              field8: this.content.field8 ? this.content.field8 : "",
              field9: this.content.field9 ? this.content.field9 : "",
              field10: this.content.field10 ? this.content.field10 : "",
              field11: this.content.field11 ? this.content.field11 : "",
              field12: this.content.field12 ? this.content.field12 : "",
              field13: this.content.field13 ? this.content.field13 : "",
              field14: this.content.field14 ? this.content.field14 : "",
              field15: this.content.field15 ? this.content.field15 : "",
              field16: this.content.field16 ? this.content.field16 : "",
              field17: this.content.field17 ? this.content.field17 : "",
              field18: this.content.field18 ? this.content.field18 : "",
              field19: this.content.field19 ? this.content.field19 : "",
              field20: this.content.field20 ? this.content.field20 : "",
              field21: this.content.field21 ? this.content.field21 : "",
              field22: this.content.field22 ? this.content.field22 : "",
              field23: this.content.field23 ? this.content.field23 : "",
              field24: this.content.field24 ? this.content.field24 : "",
              field25: this.content.field25 ? this.content.field25 : "",
            };
            this.btnLoading = true;
            this.$api.createUser(
              {data: contentSub },
              {
                onSucess: (resp) => {
                  this.btnLoading = false;
                  if (resp.data.errcode == 0) {
                    this.$message({
                      showClose: true,
                      message: this.$t("msg_save_success"),
                      type: "success",
                    });
                    this.password = "888888qqqq";
                    this.content.id = resp.data.data.id;
                    if (type == "back") {
                      this.$emit("exit");
                    } else if (type == "new") {
                      this.content = {
                        startProxyTime: "",
                        endProxyTime: "",
                        status: 1,
                        permissionType: "public",
                        roleDepartments: [],
                        departmentUser: false,
                      };
                      this.content.status =
                        this.content.status == true ? true : false;
                      this.content.permissionType =
                        this.content.permissionType == "public" ? true : false;
                      this.content.showEmail = false;
                      this.departments = [];
                      this.kmCheckRole = [];
                      this.deptRoleList = [];
                      this.fieldextends=[]
                       //请求字段扩展数据
                      // this.getFieldExtends()
                      this.getCalendars();
                      this.pwdPre = "";
                      this.loginnoFlag=false
                    } else {
                      this.$emit("refresh");
                    }
                  } else {
                    this.content.loginpwd = this.pwdPre;
                    this.$message({
                      showClose: true,
                      message: resp.data.errmsg,
                      type: "error",
                    });
                  }
                },
              }
            );
          }
        }
      });
    },
    onSaveClick(){
      this.saveBack=false;
      this.onSaveBtnClick();
    },
    onSaveAndBackClick(){
      this.saveBack=true;
      this.onSaveBtnClick();
    },

    onSaveAndNewClick(){
      this.onSaveBtnClick();
      if(!this.isAllRight){
        return false;
      }
      this.saveBack=false;
      this.content={startProxyTime:"",endProxyTime:"",status:1,permissionType:"public",roleDepartments:[], departmentUser: false};
      this.content.status=this.content.status == true? true : false
      this.content.permissionType=this.content.permissionType=='public'? true : false
      this.departments=[]
      this.kmCheckRole = []
      this.deptRoleList = []
    },

    searchTableData() {
      this.$api.getUsers(this.searchdata, {
        onSucess: resp => {
          this.tableData = resp.data.data.datas;
        }
      });
    },

    addTab() {
      let that=this;
      let newTabId = this.addDept.id;
      this.addDept.title=this.addDept.name;
      
      // this.departments.push(this.addDept)
      // let val={roleId: el.roleId, applicationId: el.applicationId, departmentId:that.addDept.id }
      let obj={
        "departmentName": that.addDept.name,
        "departmentId": that.addDept.id,
        "isDefaultDepartment": false,
        "applicationData":[],
      }
      this.customApps.forEach(elm=>{
        let app={
          "roleData":[],
          "applicationId":elm.id,
          "applicationName":elm.name,
        }
        that.defaultRole.forEach(el=>{
          if(el.applicationId==elm.id){
            let role={roleId:el.roleId,roleName:el.roleName}
            app.roleData.push(role)
          }
          
        })
        obj.applicationData.push(app);
      })
      this.deptRoleList.push(obj);
      this.editableTabsValue = newTabId;
    },
    onClearSuperiorBtn(){
      this.content.superior=null;
    },
    onClearProxyUserBtn(){
      this.content.proxyUser=null;
      this.haveProxy=false
    },
    setDefaultDept(id){
      this.content.defaultDepartment=id;
      if(this.deptRoleList.length>0){
        for(let i=0;i<this.deptRoleList.length;i++){
          if(this.content.defaultDepartment==this.deptRoleList[i].departmentId){
            if(this.deptRoleList[i].departmentName.indexOf("(默认)")==-1){
              this.deptRoleList[i].departmentName +="(默认)"
            }
            this.editableTabsValue=this.deptRoleList[i].departmentId
          }else{
            if(this.deptRoleList[i].departmentName.indexOf("(默认)")!=-1){
              this.deptRoleList[i].departmentName=this.deptRoleList[i].departmentName.substr(0,this.deptRoleList[i].departmentName.indexOf("(默认)"))
            }
          }
          
          this.deptRoleList[i].title=this.deptRoleList[i].departmentName;
        }
      }

    },
	
    setRole(id){
        let that=this;
        this.deptRoleList.forEach(elm=>{
          if(elm.departmentId==id){
            that.changeDeptRoleList=elm;
          }
        })
        this.setRoleVisiable=true;
      },
    deleteRole(deptId,applicationId,roleId){
        let index1,index2,that=this;
        this.deptRoleList.forEach((elm,ind)=>{
          if(elm.departmentId==deptId){
            index1=ind;
            elm.applicationData.forEach((el,inde)=>{
              if(el.applicationId==applicationId){
                index2=inde;
                el.roleData.forEach((elem,index)=>{
                  if(elem.roleId==roleId){
                    that.deptRoleList[index1].applicationData[index2].roleData.splice(index,1);
                  }
                })
              }
            })
          }
        })
      },
    removeTab(target) {
      let tabs = this.deptRoleList;
      // let targetNameId="";
      let activeName=this.editableTabsValue ;
      if (activeName === target) {
        tabs.forEach((tab,index) => {
          if (tab.departmentName === target) {
            let nextTab = tabs[index + 1] || tabs[index - 1];
            if (nextTab) {
              activeName = nextTab.id;
            }
          }
        });
      }
      this.editableTabsValue = activeName;
      this.deptRoleList.forEach((elm,ind)=>{
        if(elm.departmentName==target){
          this.deptRoleList.splice(ind,1)
        }
      })
      this.deptRoleList = tabs.filter(tab => tab.departmentId !== target);
      if(this.deptRoleList.length==0){
        this.content.defaultDepartment='';
        this.editableTabsValue='';
      }else if(this.deptRoleList.length>=1){
        this.setDefaultDept(this.deptRoleList[0].departmentId);
        // this.editableTabsValue=this.departments[0].name;
      }
    },
    delApplicationName(deptId,applicationId){
      let index1,that=this;
      this.$confirm(this.$t("confirm_del"), this.$t("msg_tip"), {
          confirmButtonText: this.$t('confirm'),
          cancelButtonText: this.$t('cancel'),
          type: 'warning'
        }).then(() => {
        this.deptRoleList.forEach((elm,ind)=>{
          if(elm.departmentId==deptId){
            index1=ind;
            elm.applicationData.forEach((el,inde)=>{
              if(el.applicationId==applicationId){
                  that.deptRoleList[index1].applicationData.splice(inde,1);
              }
            })
          }
        })
      })
    },
    exit(){
      this.$emit('exit')
    },
    handleClick(tab,event){
      let name='#'+tab.name
      this.$el.querySelector(name).scrollIntoView(({
        behavior: "smooth",  // 平滑过渡
      }))
    },
 }
}
</script>

<style lang="scss" scoped>

</style>